package com.model.imp;


import java.util.List;
import  org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.model.dao.AdminDao;
import com.model.entity.Admin;
import com.model.util.HibernateUtil;


public class AdminImp implements AdminDao {

	public Admin login(String name, String password) {
         String hql="from Admin where stuname=? and password=?";  
		 Session session=HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction ta=session.beginTransaction();
          Query query=session.createQuery(hql);
          query.setString(0, name);
          query.setString(1,password);
          List<Admin> list=query.list();
            ta.commit();
          for(Admin admin:list){
        	  System.out.println(admin.toString());   
        	  return  new Admin(admin.getId(), admin.getStuname(), admin.getPassword(), admin.getSex(), admin.getType(), admin.getState());
          }
		return null;
	}

}
